.class public Lde/dealdoktor/app/activities/Categories;
.super Landroid/app/Activity;
.source "Categories.java"


# instance fields
.field private categoriesListAdapter:Lde/dealdoktor/app/adapter/CategoriesListAdapter;

.field private categoriesListView:Landroid/widget/ListView;


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 14
    invoke-direct {p0}, Landroid/app/Activity;-><init>()V

    return-void
.end method


# virtual methods
.method public onClickDeselect(Landroid/view/View;)V
    .locals 3
    .parameter "v"

    .prologue
    .line 72
    const/4 v0, 0x0

    .local v0, i:I
    :goto_0
    sget-object v1, Lde/dealdoktor/app/App;->categories:Ljava/util/ArrayList;

    invoke-virtual {v1}, Ljava/util/ArrayList;->size()I

    move-result v1

    if-lt v0, v1, :cond_0

    .line 75
    return-void

    .line 73
    :cond_0
    iget-object v1, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListView:Landroid/widget/ListView;

    const/4 v2, 0x0

    invoke-virtual {v1, v0, v2}, Landroid/widget/ListView;->setItemChecked(IZ)V

    .line 72
    add-int/lit8 v0, v0, 0x1

    goto :goto_0
.end method

.method public onClickSave(Landroid/view/View;)V
    .locals 0
    .parameter "v"

    .prologue
    .line 78
    invoke-virtual {p0}, Lde/dealdoktor/app/activities/Categories;->finish()V

    .line 79
    return-void
.end method

.method public onClickSelect(Landroid/view/View;)V
    .locals 3
    .parameter "v"

    .prologue
    .line 66
    const/4 v0, 0x0

    .local v0, i:I
    :goto_0
    sget-object v1, Lde/dealdoktor/app/App;->categories:Ljava/util/ArrayList;

    invoke-virtual {v1}, Ljava/util/ArrayList;->size()I

    move-result v1

    if-lt v0, v1, :cond_0

    .line 69
    return-void

    .line 67
    :cond_0
    iget-object v1, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListView:Landroid/widget/ListView;

    const/4 v2, 0x1

    invoke-virtual {v1, v0, v2}, Landroid/widget/ListView;->setItemChecked(IZ)V

    .line 66
    add-int/lit8 v0, v0, 0x1

    goto :goto_0
.end method

.method protected onCreate(Landroid/os/Bundle;)V
    .locals 3
    .parameter "savedInstanceState"

    .prologue
    .line 21
    invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V

    .line 22
    const/high16 v1, 0x7f03

    invoke-virtual {p0, v1}, Lde/dealdoktor/app/activities/Categories;->setContentView(I)V

    .line 24
    new-instance v1, Lde/dealdoktor/app/adapter/CategoriesListAdapter;

    invoke-direct {v1, p0}, Lde/dealdoktor/app/adapter/CategoriesListAdapter;-><init>(Landroid/app/Activity;)V

    iput-object v1, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListAdapter:Lde/dealdoktor/app/adapter/CategoriesListAdapter;

    .line 26
    const v1, 0x7f0b0002

    invoke-virtual {p0, v1}, Lde/dealdoktor/app/activities/Categories;->findViewById(I)Landroid/view/View;

    move-result-object v1

    check-cast v1, Landroid/widget/ListView;

    iput-object v1, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListView:Landroid/widget/ListView;

    .line 27
    iget-object v1, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListView:Landroid/widget/ListView;

    iget-object v2, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListAdapter:Lde/dealdoktor/app/adapter/CategoriesListAdapter;

    invoke-virtual {v1, v2}, Landroid/widget/ListView;->setAdapter(Landroid/widget/ListAdapter;)V

    .line 28
    const/4 v0, 0x0

    .local v0, i:I
    :goto_0
    sget-object v1, Lde/dealdoktor/app/App;->categories:Ljava/util/ArrayList;

    invoke-virtual {v1}, Ljava/util/ArrayList;->size()I

    move-result v1

    if-lt v0, v1, :cond_0

    .line 31
    return-void

    .line 29
    :cond_0
    iget-object v2, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListView:Landroid/widget/ListView;

    sget-object v1, Lde/dealdoktor/app/App;->categories:Ljava/util/ArrayList;

    invoke-virtual {v1, v0}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lde/dealdoktor/app/data/CategoriesDAO;

    iget-boolean v1, v1, Lde/dealdoktor/app/data/CategoriesDAO;->selected:Z

    invoke-virtual {v2, v0, v1}, Landroid/widget/ListView;->setItemChecked(IZ)V

    .line 28
    add-int/lit8 v0, v0, 0x1

    goto :goto_0
.end method

.method protected onPause()V
    .locals 12

    .prologue
    .line 35
    sget-object v7, Lde/dealdoktor/app/App;->categories:Ljava/util/ArrayList;

    invoke-virtual {v7}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v7

    :goto_0
    invoke-interface {v7}, Ljava/util/Iterator;->hasNext()Z

    move-result v8

    if-nez v8, :cond_0

    .line 38
    iget-object v7, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListView:Landroid/widget/ListView;

    invoke-virtual {v7}, Landroid/widget/ListView;->getCheckItemIds()[J

    move-result-object v2

    .line 39
    .local v2, checkedIds:[J
    new-instance v5, Lde/dealdoktor/app/db/SelectedCategoriesModel;

    invoke-direct {v5, p0}, Lde/dealdoktor/app/db/SelectedCategoriesModel;-><init>(Landroid/content/Context;)V

    .line 41
    .local v5, model:Lde/dealdoktor/app/db/SelectedCategoriesModel;
    :try_start_0
    iget-object v7, v5, Lde/dealdoktor/app/db/SelectedCategoriesModel;->db:Landroid/database/sqlite/SQLiteDatabase;

    invoke-virtual {v7}, Landroid/database/sqlite/SQLiteDatabase;->beginTransaction()V

    .line 42
    invoke-virtual {v5}, Lde/dealdoktor/app/db/SelectedCategoriesModel;->deleteAll()V

    .line 43
    array-length v8, v2

    const/4 v7, 0x0

    :goto_1
    if-lt v7, v8, :cond_1

    .line 55
    iget-object v7, v5, Lde/dealdoktor/app/db/SelectedCategoriesModel;->db:Landroid/database/sqlite/SQLiteDatabase;

    invoke-virtual {v7}, Landroid/database/sqlite/SQLiteDatabase;->setTransactionSuccessful()V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Landroid/database/SQLException; {:try_start_0 .. :try_end_0} :catch_0

    .line 58
    iget-object v7, v5, Lde/dealdoktor/app/db/SelectedCategoriesModel;->db:Landroid/database/sqlite/SQLiteDatabase;

    invoke-virtual {v7}, Landroid/database/sqlite/SQLiteDatabase;->endTransaction()V

    .line 61
    :goto_2
    const/4 v7, 0x1

    sput-boolean v7, Lde/dealdoktor/app/App;->updateIndex:Z

    .line 62
    invoke-super {p0}, Landroid/app/Activity;->onPause()V

    .line 63
    return-void

    .line 35
    .end local v2           #checkedIds:[J
    .end local v5           #model:Lde/dealdoktor/app/db/SelectedCategoriesModel;
    :cond_0
    invoke-interface {v7}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lde/dealdoktor/app/data/CategoriesDAO;

    .line 36
    .local v1, category:Lde/dealdoktor/app/data/CategoriesDAO;
    invoke-virtual {v1}, Lde/dealdoktor/app/data/CategoriesDAO;->setUnselected()V

    goto :goto_0

    .line 43
    .end local v1           #category:Lde/dealdoktor/app/data/CategoriesDAO;
    .restart local v2       #checkedIds:[J
    .restart local v5       #model:Lde/dealdoktor/app/db/SelectedCategoriesModel;
    :cond_1
    :try_start_1
    aget-wide v3, v2, v7

    .line 44
    .local v3, id:J
    iget-object v9, p0, Lde/dealdoktor/app/activities/Categories;->categoriesListAdapter:Lde/dealdoktor/app/adapter/CategoriesListAdapter;

    long-to-int v10, v3

    invoke-virtual {v9, v10}, Lde/dealdoktor/app/adapter/CategoriesListAdapter;->getItem(I)Lde/dealdoktor/app/data/CategoriesDAO;

    move-result-object v1

    .line 45
    .restart local v1       #category:Lde/dealdoktor/app/data/CategoriesDAO;
    iget v9, v1, Lde/dealdoktor/app/data/CategoriesDAO;->id:I

    invoke-virtual {v5, v9}, Lde/dealdoktor/app/db/SelectedCategoriesModel;->insert(I)V

    .line 46
    iget-object v9, v1, Lde/dealdoktor/app/data/CategoriesDAO;->subCategories:Ljava/util/ArrayList;

    invoke-virtual {v9}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v9

    :goto_3
    invoke-interface {v9}, Ljava/util/Iterator;->hasNext()Z

    move-result v10

    if-nez v10, :cond_3

    .line 49
    sget-object v9, Lde/dealdoktor/app/App;->categories:Ljava/util/ArrayList;

    invoke-virtual {v9}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v9

    :cond_2
    :goto_4
    invoke-interface {v9}, Ljava/util/Iterator;->hasNext()Z

    move-result v10

    if-nez v10, :cond_4

    .line 43
    add-int/lit8 v7, v7, 0x1

    goto :goto_1

    .line 46
    :cond_3
    invoke-interface {v9}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v6

    check-cast v6, Lde/dealdoktor/app/data/CategoriesDAO;

    .line 47
    .local v6, subCategory:Lde/dealdoktor/app/data/CategoriesDAO;
    iget v10, v6, Lde/dealdoktor/app/data/CategoriesDAO;->id:I

    invoke-virtual {v5, v10}, Lde/dealdoktor/app/db/SelectedCategoriesModel;->insert(I)V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0
    .catch Landroid/database/SQLException; {:try_start_1 .. :try_end_1} :catch_0

    goto :goto_3

    .line 56
    .end local v1           #category:Lde/dealdoktor/app/data/CategoriesDAO;
    .end local v3           #id:J
    .end local v6           #subCategory:Lde/dealdoktor/app/data/CategoriesDAO;
    :catch_0
    move-exception v7

    .line 58
    iget-object v7, v5, Lde/dealdoktor/app/db/SelectedCategoriesModel;->db:Landroid/database/sqlite/SQLiteDatabase;

    invoke-virtual {v7}, Landroid/database/sqlite/SQLiteDatabase;->endTransaction()V

    goto :goto_2

    .line 49
    .restart local v1       #category:Lde/dealdoktor/app/data/CategoriesDAO;
    .restart local v3       #id:J
    :cond_4
    :try_start_2
    invoke-interface {v9}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lde/dealdoktor/app/data/CategoriesDAO;

    .line 50
    .local v0, cat:Lde/dealdoktor/app/data/CategoriesDAO;
    iget v10, v0, Lde/dealdoktor/app/data/CategoriesDAO;->id:I

    iget v11, v1, Lde/dealdoktor/app/data/CategoriesDAO;->id:I

    if-ne v10, v11, :cond_2

    .line 51
    invoke-virtual {v1}, Lde/dealdoktor/app/data/CategoriesDAO;->setSelected()V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0
    .catch Landroid/database/SQLException; {:try_start_2 .. :try_end_2} :catch_0

    goto :goto_4

    .line 57
    .end local v0           #cat:Lde/dealdoktor/app/data/CategoriesDAO;
    .end local v1           #category:Lde/dealdoktor/app/data/CategoriesDAO;
    .end local v3           #id:J
    :catchall_0
    move-exception v7

    .line 58
    iget-object v8, v5, Lde/dealdoktor/app/db/SelectedCategoriesModel;->db:Landroid/database/sqlite/SQLiteDatabase;

    invoke-virtual {v8}, Landroid/database/sqlite/SQLiteDatabase;->endTransaction()V

    .line 59
    throw v7
.end method
